#include "StdAfx.h"
#include "ParticleEntityBody.h"


ParticleEntityBody::ParticleEntityBody(Ogre::SceneNode * node, Ogre::SceneManager * scnMgr, Ogre::String scriptName,Ogre::String bodyName, std::deque<Ogre::ParticleSystem*> * particleSystems)
{
	sceneMgr = scnMgr;
	psNode = node;
	
	
	pSystem = sceneMgr->createParticleSystem(bodyName, scriptName);
	particleSystems->push_front(pSystem);
	psNode->attachObject(pSystem);
}


ParticleEntityBody::~ParticleEntityBody(void)
{
	
	/*pSystem->detachFromParent();
	sceneMgr->destroyParticleSystem(pSystem->getName());*/

}



void ParticleEntityBody::setPosition(Ogre::Vector3 position)
{
	lastPosition = position;
	psNode->_setDerivedPosition(position);
}

Ogre::Vector3 ParticleEntityBody::getPosition()
{
	return psNode->_getDerivedPosition();
}

void ParticleEntityBody::setOrientation(Ogre::Quaternion orientation)
{
	lastOrientation = orientation;
	psNode->_setDerivedOrientation(orientation);
}

Ogre::Quaternion ParticleEntityBody::getOrientation()
{
	return psNode->_getDerivedOrientation();
}

void ParticleEntityBody::setLocalPosition(Ogre::Vector3 position)
{
	psNode->setPosition(position);
}

Ogre::Vector3 ParticleEntityBody::getLocalPosition()
{
	return psNode->getPosition();
}

void ParticleEntityBody::setLocalOrientation(Ogre::Quaternion orientation)
{
	psNode->setOrientation(orientation);
}

Ogre::Quaternion ParticleEntityBody::getLocalOrientation()
{
	return psNode->getOrientation();
}



void ParticleEntityBody::setLookAt(Ogre::Vector3 target)
{
	psNode->lookAt(target,Ogre::Node::TS_WORLD);
}
	
Ogre::Vector3 ParticleEntityBody::getFacingDir()
{
	Ogre::Quaternion ori = getOrientation();

	return ori*Ogre::Vector3::UNIT_Z;
}

Ogre::SceneNode*  ParticleEntityBody::getParentNode()
{
	return psNode;
}



void ParticleEntityBody::addForce(Ogre::Vector3 force)
{
}

void ParticleEntityBody::addTorque(Ogre::Vector3 torque)
{
}

void ParticleEntityBody::killBody()
{

	pSystem->setEmitting(false);
	
}